package mrusanov.ui.battle.actions

class ActionList(actions:List[Action]) extends Action {
  def update(time:Int) {
    executeActions(time)
    isCompleted = actions forall(_.isCompleted)
  }

  private def executeActions(time:Int) {
    val nonCompleted = actions filterNot (_.isCompleted)
    var timeTakingActionExecuted = false

    nonCompleted.foreach(ac => {
      if (!ac.isMomentary && timeTakingActionExecuted) {
        return
      }

      ac.update(time)
      if (!ac.isMomentary) {
        timeTakingActionExecuted = true
      }
    })
  }

  val isMomentary = actions forall(_.isMomentary)

}
